package com.bear.atlassianmcp.jira.exception;

/**
 * Jira集成异常类
 * 用于封装Jira API调用过程中的各种异常情况
 */
public class JiraIntegrationException extends RuntimeException {

    private final String errorCode;
    private final int httpStatus;

    public JiraIntegrationException(String message) {
        super(message);
        this.errorCode = "JIRA_ERROR";
        this.httpStatus = 500;
    }

    public JiraIntegrationException(String message, Throwable cause) {
        super(message, cause);
        this.errorCode = "JIRA_ERROR";
        this.httpStatus = 500;
    }

    public JiraIntegrationException(String message, String errorCode, int httpStatus) {
        super(message);
        this.errorCode = errorCode;
        this.httpStatus = httpStatus;
    }

    public JiraIntegrationException(String message, String errorCode, int httpStatus, Throwable cause) {
        super(message, cause);
        this.errorCode = errorCode;
        this.httpStatus = httpStatus;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public int getHttpStatus() {
        return httpStatus;
    }

    /**
     * 创建认证失败异常
     */
    public static JiraIntegrationException authenticationFailed(String message) {
        return new JiraIntegrationException(message, "AUTH_FAILED", 401);
    }

    /**
     * 创建权限不足异常
     */
    public static JiraIntegrationException accessDenied(String message) {
        return new JiraIntegrationException(message, "ACCESS_DENIED", 403);
    }

    /**
     * 创建资源未找到异常
     */
    public static JiraIntegrationException notFound(String message) {
        return new JiraIntegrationException(message, "NOT_FOUND", 404);
    }

    /**
     * 创建网络连接异常
     */
    public static JiraIntegrationException connectionFailed(String message, Throwable cause) {
        return new JiraIntegrationException(message, "CONNECTION_FAILED", 503, cause);
    }

    /**
     * 创建API调用异常
     */
    public static JiraIntegrationException apiCallFailed(String message, int httpStatus) {
        return new JiraIntegrationException(message, "API_CALL_FAILED", httpStatus);
    }
}
